home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 March / EnigmA AMIGA RUN 05 (1996)(G.R. Edizioni)(IT)[!][issue 1996-03][Skylink CD IV].iso / earcd / comm2 / amislt14.lha / AmiSlate / SlateRexx / vector.rexx < prev   
OS/2 REXX Batch file  |  1996-01-27  |  7KB  |  517 lines

  1. /* An Arexx script for use with AmiSlate:  
  2.  
  3.   Wire vector graphics for AmiSlate.
  4.  
  5.   Copyright (c) 1995,1996 Johan Torin  (johan@artworks.apana.org.au)
  6.  
  7.   Minor enhancements by Jeremy Friesner (jfriesne@ucsd.edu)
  8.   
  9.   Very simple example of AmiSlates arexx capabilities. Not optimized very
  10.   much (just a sine and cosine lookup table).  On my A3000 the speed is 
  11.   comparable to a 386SX/40MHz running more or less the same code, through 
  12.   Microsoft Quickbasic... :)
  13.  
  14.   Requires RexxMathlLib.library to run, can be found on AmiNet as:
  15.   RexxMathLib1.3.lha  util/rexx  13K+ARexx function library, version 1.3
  16.  
  17.   To aviod flicker, due to long redraw time, this vector drawing routine
  18.   uses a special trick, ie. it redraw one line at a time. This is the reason
  19.   for the jerky look of the objects.
  20.  
  21. */
  22.  
  23. parse arg CommandPort ActiveString
  24.  
  25. address (CommandPort)
  26.  
  27. if (length(CommandPort) == 0) then do
  28.     say ""
  29.     say "Usage:  rx Vector.rexx <REXXPORTNAME>"
  30.     say "        (REXXPORTNAME is usually AMISLATE)"
  31.     say ""
  32.     say "Or run from the Rexx menu within AmiSlate."
  33.     say ""
  34.     exit 0
  35.     end
  36.  
  37. options results
  38.  
  39. /* Add library if not done before */
  40. If ~Show('L',"rexxmathlib.library") then do
  41.    If addlib('rexxmathlib.library',0,-30,0) then
  42.       nop
  43.    else do
  44.       Say "Couldn't open RexxMathlib.library!"
  45.       exit 10
  46.       end
  47.    end  
  48.  
  49.  
  50. EasyRequest "Vector" '"'||"Which shape do you wish to see?"||'"' "Cube|Ball"
  51.  
  52. /* Get object */
  53. if (rc == 1) then do
  54.     call Cube
  55.     Shape = CUBE
  56.     end
  57. else do
  58.     call Ball
  59.     Shape = BALL
  60.     end
  61.  
  62. /* Init some variables */
  63. XPP2 = 0
  64. YPP2 = 0
  65. ZPP2 = 0
  66. YPP2 = 0
  67. XPP3 = 0
  68. ZPP2 = 0
  69. PE = 0
  70. A = 0
  71.  
  72. Do I = 1 TO RealCordNum
  73.    PSX.I = 0
  74.    PSY.I = 0
  75.    PSXOld.I = 0
  76.    PSYOld.I = 0
  77. End
  78.  
  79. if (Shape = CUBE) then Dist = 5000
  80.           else Dist = 1000
  81.           
  82. Q1 = 0
  83. Q2 = 0
  84. Q3 = 0
  85.  
  86. DecIn = 10
  87. TempDecIn = -10
  88.  
  89. /* Get windowsize */
  90. GetWindowAttrs stem winattrs.
  91. XG = (winattrs.width  - 58) / 2
  92. YG = (winattrs.height - 53) / 2
  93.  
  94. SetWindowTitle '"' || "Setting up rotation tables... 628" || '"'
  95.  
  96. /* Setup sine & cosine tables */
  97. do i = 0 to 628
  98.     QuickSin.i = SIN(i/100)
  99.     QuickCos.i = COS(i/100)
  100.     if ((i//23) == 0) then SetWindowTitle '"' || "Setting up rotation tables... " || 628-i || '"'
  101.     end
  102.  
  103. SetWindowTitle '"' || "Whee!  3D!" || '"'
  104.  
  105. Do Forever
  106.    Call Rotate
  107.  
  108.    Q2 = (Q2 + 8) // 628
  109. /* Q1 = (Q1 + 12) // 628 */
  110.    Q3 = (Q3 + 16) // 628
  111.  
  112.    If Dist > 600 Then Do
  113.       Dist = Dist - 160
  114.       End
  115. End
  116.  
  117. Rotate:
  118.  
  119. Do Cord = 1 TO RealCordNum
  120.    XPP2 = XPP.Cord
  121.    YPP2 = YPP.Cord
  122.    ZPP2 = ZPP.Cord * QuickCos.Q2 - YPP2 * QuickSin.Q2
  123.    YPP2 = YPP2 * QuickCos.Q2 + ZPP.Cord * QuickSin.Q2
  124.    XPP3 = XPP2 * QuickCos.Q3 - ZPP2 * QuickSin.Q3
  125.    ZPP2 = ZPP2 * QuickCos.Q3 + XPP2 * QuickSin.Q3
  126.    PE = 128000 / (Dist + ZPP2)
  127.    PSXOld.Cord = PSX.Cord
  128.    PSYOld.Cord = PSY.Cord
  129.    PSX.Cord = Trunc((XPP3 * PE) / 256 + XG)
  130.    PSY.Cord = Trunc((YPP2 * PE) / 256 + YG)
  131. End
  132.  
  133. Do Lin = 1 TO RealLineNum
  134.    TL1 = L1.Lin
  135.    TL2 = L2.Lin
  136.    SetFPen 0
  137.    Line PSXOld.TL1 PSYOld.TL1 PSXOld.TL2 PSYOld.TL2 
  138.    SetFPen 1
  139.    Line PSX.TL1 PSY.TL1 PSX.TL2 PSY.TL2 
  140. End
  141.  
  142. Do L = 1 TO RealCordNum
  143.    PSXOld.L = PSX.L
  144.    PSYOld.L = PSY.L
  145. End
  146.  
  147. Return
  148.  
  149.  
  150. Cube:
  151. XPP.1 = -60
  152. YPP.1 = -60
  153. ZPP.1 = 60
  154. XPP.2 = -60
  155. YPP.2 = 60
  156. ZPP.2 = 60
  157. XPP.3 = 60
  158. YPP.3 = 60
  159. ZPP.3 = 60
  160. XPP.4 = 60
  161. YPP.4 = -60
  162. ZPP.4 = 60
  163. XPP.5 = -60
  164. YPP.5 = -60
  165. ZPP.5 = -60
  166. XPP.6 = -60
  167. YPP.6 = 60
  168. ZPP.6 = -60
  169. XPP.7 = 60
  170. YPP.7 = 60
  171. ZPP.7 = -60
  172. XPP.8 = 60
  173. YPP.8 = -60
  174. ZPP.8 = -60
  175.  
  176. L1.1 = 1
  177. L2.1 = 2
  178. L1.2 = 2
  179. L2.2 = 3
  180. L1.3 = 3
  181. L2.3 = 4
  182. L1.4 = 4
  183. L2.4 = 1
  184. L1.5 = 5
  185. L2.5 = 6
  186. L1.6 = 6
  187. L2.6 = 7
  188. L1.7 = 7
  189. L2.7 = 8
  190. L1.8 = 8
  191. L2.8 = 5
  192. L1.9 = 1
  193. L2.9 = 5
  194. L1.10 = 2
  195. L2.10 = 6
  196. L1.11 = 3
  197. L2.11 = 7
  198. L1.12 = 4
  199. L2.12 = 8
  200.  
  201. RealCordNum = 8
  202. RealLineNum = 12
  203. Return
  204.  
  205.  
  206. Ball:
  207. XPP.1 = 0
  208. YPP.1 = 0
  209. ZPP.1 = -30
  210. XPP.2 = 0
  211. YPP.2 = -20
  212. ZPP.2 = -25
  213. XPP.3 = 14
  214. YPP.3 = -15
  215. ZPP.3 = -25
  216. XPP.4 = 20
  217. YPP.4 = 0
  218. ZPP.4 = -25
  219. XPP.5 = 14
  220. YPP.5 = 14
  221. ZPP.5 = -25
  222. XPP.6 = -1
  223. YPP.6 = 20
  224. ZPP.6 = -25
  225. XPP.7 = -15
  226. YPP.7 = 14
  227. ZPP.7 = -25
  228. XPP.8 = -20
  229. YPP.8 = -1
  230. ZPP.8 = -25
  231. XPP.9 = -15
  232. YPP.9 = -15
  233. ZPP.9 = -25
  234. XPP.10 = 0
  235. YPP.10 = -40
  236. ZPP.10 = -15
  237. XPP.11 = 28
  238. YPP.11 = -29
  239. ZPP.11 = -15
  240. XPP.12 = 40
  241. YPP.12 = 0
  242. ZPP.12 = -15
  243. XPP.13 = 28
  244. YPP.13 = 28
  245. ZPP.13 = -15
  246. XPP.14 = -1
  247. YPP.14 = 40
  248. ZPP.14 = -15
  249. XPP.15 = -29
  250. YPP.15 = 28
  251. ZPP.15 = -15
  252. XPP.16 = -40
  253. YPP.16 = -1
  254. ZPP.16 = -15
  255. XPP.17 = -29
  256. YPP.17 = -29
  257. ZPP.17 = -15
  258. XPP.18 = 0
  259. YPP.18 = -60
  260. ZPP.18 = 0
  261. XPP.19 = 42
  262. YPP.19 = -43
  263. ZPP.19 = 0
  264. XPP.20 = 60
  265. YPP.20 = 0
  266. ZPP.20 = 0
  267. XPP.21 = 42
  268. YPP.21 = 42
  269. ZPP.21 = 0
  270. XPP.22 = -1
  271. YPP.22 = 60
  272. ZPP.22 = 0
  273. XPP.23 = -43
  274. YPP.23 = 42
  275. ZPP.23 = 0
  276. XPP.24 = -60
  277. YPP.24 = -1
  278. ZPP.24 = 0
  279. XPP.25 = -43
  280. YPP.25 = -43
  281. ZPP.25 = 0
  282. XPP.26 = 0
  283. YPP.26 = -40
  284. ZPP.26 = 15
  285. XPP.27 = 28
  286. YPP.27 = -29
  287. ZPP.27 = 15
  288. XPP.28 = 40
  289. YPP.28 = 0
  290. ZPP.28 = 15
  291. XPP.29 = 28
  292. YPP.29 = 28
  293. ZPP.29 = 15
  294. XPP.30 = -1
  295. YPP.30 = 40
  296. ZPP.30 = 15
  297. XPP.31 = -29
  298. YPP.31 = 28
  299. ZPP.31 = 15
  300. XPP.32 = -40
  301. YPP.32 = -1
  302. ZPP.32 = 15
  303. XPP.33 = -29
  304. YPP.33 = -29
  305. ZPP.33 = 15
  306. XPP.34 = 0
  307. YPP.34 = -20
  308. ZPP.34 = 25
  309. XPP.35 = 14
  310. YPP.35 = -15
  311. ZPP.35 = 25
  312. XPP.36 = 20
  313. YPP.36 = 0
  314. ZPP.36 = 25
  315. XPP.37 = 14
  316. YPP.37 = 14
  317. ZPP.37 = 25
  318. XPP.38 = -1
  319. YPP.38 = 20
  320. ZPP.38 = 25
  321. XPP.39 = -15
  322. YPP.39 = 14
  323. ZPP.39 = 25
  324. XPP.40 = -20
  325. YPP.40 = -1
  326. ZPP.40 = 25
  327. XPP.41 = -15
  328. YPP.41 = -15
  329. ZPP.41 = 25
  330. XPP.42 = 0
  331. YPP.42 = 0
  332. ZPP.42 = 30
  333.  
  334.  
  335.  
  336.  
  337. L1.1 = 2
  338. L2.1 = 3
  339. L1.2 = 3
  340. L2.2 = 4
  341. L1.3 = 4
  342. L2.3 = 5
  343. L1.4 = 5
  344. L2.4 = 6
  345. L1.5 = 6
  346. L2.5 = 7
  347. L1.6 = 7
  348. L2.6 = 8
  349. L1.7 = 8
  350. L2.7 = 9
  351. L1.8 = 9
  352. L2.8 = 2
  353. L1.9 = 1
  354. L2.9 = 2
  355. L1.10 = 1
  356. L2.10 = 3
  357. L1.11 = 1
  358. L2.11 = 4
  359. L1.12 = 1
  360. L2.12 = 5
  361. L1.13 = 1
  362. L2.13 = 6
  363. L1.14 = 1
  364. L2.14 = 7
  365. L1.15 = 1
  366. L2.15 = 8
  367. L1.16 = 1
  368. L2.16 = 9
  369. L1.17 = 10
  370. L2.17 = 11
  371. L1.18 = 11
  372. L2.18 = 12
  373. L1.19 = 12
  374. L2.19 = 13
  375. L1.20 = 13
  376. L2.20 = 14
  377. L1.21 = 14
  378. L2.21 = 15
  379. L1.22 = 15
  380. L2.22 = 16
  381. L1.23 = 16
  382. L2.23 = 17
  383. L1.24 = 17
  384. L2.24 = 10
  385. L1.25 = 2
  386. L2.25 = 10
  387. L1.26 = 3
  388. L2.26 = 11
  389. L1.27 = 4
  390. L2.27 = 12
  391. L1.28 = 5
  392. L2.28 = 13
  393. L1.29 = 6
  394. L2.29 = 14
  395. L1.30 = 7
  396. L2.30 = 15
  397. L1.31 = 8
  398. L2.31 = 16
  399. L1.32 = 9
  400. L2.32 = 17
  401. L1.33 = 18
  402. L2.33 = 19
  403. L1.34 = 19
  404. L2.34 = 20
  405. L1.35 = 20
  406. L2.35 = 21
  407. L1.36 = 21
  408. L2.36 = 22
  409. L1.37 = 22
  410. L2.37 = 23
  411. L1.38 = 23
  412. L2.38 = 24
  413. L1.39 = 24
  414. L2.39 = 25
  415. L1.40 = 25
  416. L2.40 = 18
  417. L1.41 = 10
  418. L2.41 = 18
  419. L1.42 = 11
  420. L2.42 = 19
  421. L1.43 = 12
  422. L2.43 = 20
  423. L1.44 = 13
  424. L2.44 = 21
  425. L1.45 = 14
  426. L2.45 = 22
  427. L1.46 = 15
  428. L2.46 = 23
  429. L1.47 = 16
  430. L2.47 = 24
  431. L1.48 = 17
  432. L2.48 = 25
  433. L1.49 = 26
  434. L2.49 = 27
  435. L1.50 = 27
  436. L2.50 = 28
  437. L1.51 = 28
  438. L2.51 = 29
  439. L1.52 = 29
  440. L2.52 = 30
  441. L1.53 = 30
  442. L2.53 = 31
  443. L1.54 = 31
  444. L2.54 = 32
  445. L1.55 = 32
  446. L2.55 = 33
  447. L1.56 = 33
  448. L2.56 = 26
  449. L1.57 = 26
  450. L2.57 = 18
  451. L1.58 = 27
  452. L2.58 = 19
  453. L1.59 = 28
  454. L2.59 = 20
  455. L1.60 = 29
  456. L2.60 = 21
  457. L1.61 = 30
  458. L2.61 = 22
  459. L1.62 = 31
  460. L2.62 = 23
  461. L1.63 = 32
  462. L2.63 = 24
  463. L1.64 = 33
  464. L2.64 = 25
  465. L1.65 = 34
  466. L2.65 = 35
  467. L1.66 = 35
  468. L2.66 = 36
  469. L1.67 = 36
  470. L2.67 = 37
  471. L1.68 = 37
  472. L2.68 = 38
  473. L1.69 = 38
  474. L2.69 = 39
  475. L1.70 = 39
  476. L2.70 = 40
  477. L1.71 = 40
  478. L2.71 = 41
  479. L1.72 = 41
  480. L2.72 = 34
  481. L1.73 = 34
  482. L2.73 = 26
  483. L1.74 = 35
  484. L2.74 = 27
  485. L1.75 = 36
  486. L2.75 = 28
  487. L1.76 = 37
  488. L2.76 = 29
  489. L1.77 = 38
  490. L2.77 = 30
  491. L1.78 = 39
  492. L2.78 = 31
  493. L1.79 = 40
  494. L2.79 = 32
  495. L1.80 = 41
  496. L2.80 = 33
  497. L1.81 = 34
  498. L2.81 = 42
  499. L1.82 = 35
  500. L2.82 = 42
  501. L1.83 = 36
  502. L2.83 = 42
  503. L1.84 = 37
  504. L2.84 = 42
  505. L1.85 = 38
  506. L2.85 = 42
  507. L1.86 = 39
  508. L2.86 = 42
  509. L1.87 = 40
  510. L2.87 = 42
  511. L1.88 = 41
  512. L2.88 = 42
  513.  
  514. RealCordNum = 42
  515. RealLineNum = 88
  516. Return
  517.